$(document).ready(function() {
	//实名认证
	$("#sect_author").click(function(){
		if($("#sect_author_div").is(":hidden")){
			$("#sect_author_div").show();
		}else{
			$("#sect_author_div").hide();
		}
	});
	$("#realNameAuth").click(function(){
		var realName=$("#realName").val().trim();
		var certNo=$("#certNo").val().trim();
		if(Helper.isEmpty(realName)){
			Helper.message("请输入真实姓名");
			return;
		}
		if(Helper.isEmpty(certNo)){
			Helper.message("请输入身份证号码");
			return;
		}
		if(!Helper.validata.isIdCardNo(certNo)){
			Helper.message("身份证号码不正确");
			return;
		}
		if(!Helper.validata.suiTableAge(certNo)) {
			Helper.message("必须年满18周岁");
			return;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/realNameAuth.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					//$("#realName").attr("disabled","disabled");
					//$("#certNo").attr("disabled","disabled");
					//$("#realNameAuth").hide();
					//$("#sect_authno_css").attr("class","sect_auth_ism");
					//Helper.message("实名认证成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				$("realNameAuth").attr("disabled","");
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {realName:realName,cardNumber:certNo};
		$(this).attr("disabled","disabled");
		remoteTrans.send();
	});
	//修改密码
	$("#sect_pwd_c").click(function(){
		if($("#updatePassword_div").is(":hidden")){
			$("#updatePassword_div").show();
		}else{
			$("#updatePassword_div").hide();
		}
		
	}); 
	$("#updatepwd").click(function(){
		
		var oldPassword=$("#oldPassword").val().trim();
		var password1=$("#npswd").val().trim();
		var password2=$("#enterpwd").val().trim();
		if(Helper.isEmpty(oldPassword)){
			Helper.message("请输入旧登录密码");
			return;
		}
		if(Helper.isEmpty(password1)){
			Helper.message("请输入新登录密码");
			return;
		}
		if(oldPassword==password1){
			Helper.message("旧密码和新密码不能相同");
			return;
		}
		var validatapass=Helper.validata.validataPass(password1);
		if(validatapass){
			alert(validatapass);
			return;
		}
		if(password1!=password2){
			Helper.message("重复密码和新密码不一致");
			return;
		}
		
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/updatePassword.htm",
			onSuccess:function(json) {
				$("updatepwd").attr("disabled","");
				if(json.isSuccess==true){
					$("#oldPassword").val("");
					$("#npswd").val("");
					$("#enterpwd").val("");
					Helper.message("修改密码成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
				}else{
					
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {oldPassword:oldPassword,password:password1};
		remoteTrans.send();
		
	});
	//设置安全问题
	$("#sect_bereq_b").click(function(){
		if($("#question_div").is(":hidden")){
			$("#question_div").show();
		}else{
			$("#question_div").hide();
		}
	});
	
	//设置安全问题
	$("#bdsaftyproblem").click(function(){
		var questionTypeOne=$("#questionTypeOne").val();
		var answerOne=$("#answerOne").val();
		if(Helper.isEmpty(questionTypeOne)){
			Helper.message("请选择安全问题");
			return;
		}
		if(Helper.isEmpty(answerOne)){
			Helper.message("请填写安全问题答案");
			return;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/doSetQuestion.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					$("#answerOne").val("");
					$("#sect_bereq_b").hide();
					$("#question_div").hide();
					$("#question_ico").attr("class","sect_auth_ism");
					Helper.message("设置密保成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {questionType:questionTypeOne,answer:answerOne};
		remoteTrans.send();
		
	});
	
	//修改安全问题
	$("#sect_bereq_c").click(function(){
		if($("#question_update_div").is(":hidden")){
			$("#question_update_div").show();
		}else{
			$("#question_update_div").hide();
		}
	});
	
	$("#bdsaftyproblemnew").click(function(){
		var questionTypeold=$("#questionTypeold").val();
		var answerold=$("#answerold").val();
		var questionTypenew=$("#questionTypenew").val();
		var answernew=$("#answernew").val();
		if(Helper.isEmpty(questionTypeold)){
			Helper.message("请选择老安全问题");
			return;
		}
		if(Helper.isEmpty(answerold)){
			Helper.message("请填写老安全问题答案");
			return;
		}
		if(Helper.isEmpty(questionTypenew)){
			Helper.message("请选择新安全问题");
			return;
		}
		if(Helper.isEmpty(answernew)){
			Helper.message("请填写新安全问题答案");
			return;
		}
		if(questionTypeold==questionTypenew){
			Helper.message("安全问题不能相同");
			return;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/upSetQuestion.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					$("#answerold").val("");
					$("#answernew").val("");
					$("#question_update_div").hide();
					Helper.message("设置密保成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {questionTypeold:questionTypeold,answerold:answerold,questionTypenew:questionTypenew,answernew:answernew};
		remoteTrans.send();
		
	});
	
	
	//邮箱验证
	$("#sect_bemail_b").click(function(){
		if($("#sect_bemail_bo").is(":hidden")){
			$("#sect_bemail_bo").show();
		}else{
			$("#sect_bemail_bo").hide();
		}
	});
	$("#sect_bemail_c").click(function(){
		if($("#sect_cemail_boc").is(":hidden")){
			$("#sect_cemail_boc").show();
		}else{
			$("#sect_cemail_boc").hide();
		}
	});
	//绑定邮箱
	$("#tipsemail_tj").click(function(){
		var emailaddres=$("#emailaddres").val();
		var validataEmail=Helper.validata.validataEmail(emailaddres);
		if(validataEmail){
			Helper.message(validataEmail);
			return;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/sendValidEmail.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					Helper.message("已经发送到你邮箱，请注意查收！");
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {email:emailaddres,returnUrl:Helper.basePath+"/page/account/my/validEmail.jsp"};
		remoteTrans.send();
	});
	//修改邮箱
	$("#tipsemail_fs").click(function(){
		var oldemail=$("#oldemail").val();
		var validataOldemail=Helper.validata.validataEmail(oldemail);
		if(validataOldemail){
			Helper.message("老"+validataOldemail);
			return;
		}
		var newemail=$("#newemail").val();
		var validataEmail=Helper.validata.validataEmail(newemail);
		if(validataEmail){
			Helper.message("新"+validataEmail);
			return;
		}
		if(oldemail==newemail){
			Helper.message("邮箱不能一样");
			return;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/sendValidEmailCX.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					$("#emailaddres").val("");
					Helper.message("已经发送到你邮箱，请注意查收！");
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {oldemail:oldemail,newemail:newemail,returnUrl:Helper.basePath+"/page/account/my/validEmail.jsp"};
		remoteTrans.send();
		
	});
	
	//手机绑定
	$("#sect_mo_bind").click(function(){
		if($("#mobilech").is(":hidden")){
			$("#mobilech").show();
		}else{
			$("#mobilech").hide();
		}
	});
	//手机绑定
	$("#sect_ch_mobilecode_g").click(function(){
		var sect_mobile_ch=$("#sect_mobile_ch").val();
		var validataMobile=Helper.validata.validataMobile(sect_mobile_ch);
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/sendValidSMS.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					var timeInterval=json.returnValue;
					$("#sect_ch_mobilecode_g").hide();
					$("#sect_ch_mobilecode_h").show();
					var timmer=new Helper.Timmer({
						milli:1000,
						count:timeInterval,
						call:function(){
							timeInterval=timeInterval-1;
							if( timeInterval> 0) {
								$("#sect_ch_mobilecode_h").val(timeInterval+"秒后可重发");
							}else{
								$("#sect_ch_mobilecode_g").show();
								$("#sect_ch_mobilecode_h").hide();
							}
						}
					});
					Helper.message("短信发送成功，请注意查收！");
					timmer.start();
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {mobile:sect_mobile_ch};
		remoteTrans.send();
	});
	//手机号码绑定
	$("#changemobilenext").click(function(){
		var sect_mobile_ch=$("#sect_mobile_ch").val();
		var sect_ch_mobilecode=$("#sect_ch_mobilecode").val();
		var validataMobile=Helper.validata.validataMobile(sect_mobile_ch);
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		if(Helper.isEmpty(sect_ch_mobilecode)){
			Helper.message("短信验证码不能为空");
			return ;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/doValidSMS.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					$("#mobilech").hide();
					$("#sect_mo_bind").hide();
					$("#sect_mo_ch").show();
					$("#sect_oldmobile").val(sect_mobile_ch);
					$("#mobileCheckCSS").attr("class","sect_auth_ism");
					Helper.message("手机绑定成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
					
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {mobile:sect_mobile_ch,code:sect_ch_mobilecode};
		remoteTrans.send();
	});
	
	
	//修改手机绑定
	$("#sect_mo_ch").click(function(){
		if($("#setnewmobile").is(":hidden")){
			$("#setnewmobile").show();
		}else{
			$("#setnewmobile").hide();
		}
	});
	
	
	
	//发送短信验证码
	$("#sect_new_mobilecode_g").click(function(){
		var sect_oldmobile=$("#sect_oldmobile").val();
		var sect_newmobile=$("#sect_newmobile").val();
		var validataMobile=Helper.validata.validataMobile(sect_newmobile);
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		if(sect_newmobile==sect_oldmobile){
			Helper.message("新老手机不能一样");
			return ;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/sendValidSMS.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					var timeInterval=json.returnValue;
					$("#sect_new_mobilecode_g").hide();
					$("#sect_new_mobilecode_h").show();
					var timmer=new Helper.Timmer({
						milli:1000,
						count:timeInterval,
						call:function(){
							timeInterval=timeInterval-1;
							if( timeInterval> 0) {
								$("#sect_new_mobilecode_h").val(timeInterval+"秒后可重发");
							}else{
								$("#sect_new_mobilecode_g").show();
								$("#sect_new_mobilecode_h").hide();
							}
						}
					});
					Helper.message("短信发送成功，请注意查收！");
					timmer.start();
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {mobile:sect_newmobile};
		remoteTrans.send();
	});
	
	//修改手机号码
	$("#upmobile").click(function(){
		var sect_oldmobile=$("#sect_oldmobile").val();
		var sect_newmobile=$("#sect_newmobile").val();
		var sect_new_mobilecode=$("#sect_new_mobilecode").val();
		var validataMobile=Helper.validata.validataMobile(sect_newmobile);
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		if(sect_newmobile==sect_oldmobile){
			Helper.message("新老手机不能一样");
			return ;
		}
		if(Helper.isEmpty(sect_new_mobilecode)){
			Helper.message("短信验证码不能为空");
			return ;
		}
		var remoteTrans = new Helper.RemoteTrans({
			url:Helper.basePath+"/memberCenter/doValidSMS.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					$("#sect_oldmobile").val(sect_newmobile);
					$("#sect_newmobile").val("");
					$("#sect_new_mobilecode").val("");
					Helper.message("手机绑定修改成功");
					location.replace(Helper.basePath+"/memberCenter/toPersonSet.htm");
					$("#setnewmobile").hide();
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		remoteTrans.params = {mobile:sect_newmobile,code:sect_new_mobilecode};
		remoteTrans.send();
	});
});